package com.sangmo.fts.basic.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "document_template")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class DocumentTemplate extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.STRING_50, required = true, index = true)
    private String name;

    @DataField(value = IConstants.DATA_TYPE.STRING_10, required = true)
    private String type;

    @One(value = "document", target = FileUpload.class, fieldset = {"id","url","fileName"}, groups = {"DocumentTemplate.search"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long docId;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Long getDocId() {
        return docId;
    }

    public void setDocId(Long docId) {
        this.docId = docId;
    }
}
